package com.mall.admin.service;

import com.mall.autoconfig.template.OssTemplate;
import com.mall.commons.utils.R;
import org.omg.CORBA_2_3.portable.InputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Service
public class OssService {

    @Autowired
    private OssTemplate ossTemplate;

    /**
     * 图片上传
     * @param photoFile
     * @return
     */
    public R savePic(MultipartFile photoFile) throws IOException {
        String pic = ossTemplate.upload(photoFile.getOriginalFilename(),photoFile.getInputStream());
        Map<String,String> url=new HashMap<>();
        url.put("url",pic);
        return R.success("图片上传",url);
    }
}